﻿using System;

using Elifart.Library.Utils;
using System.Collections.Generic;

namespace Elifart.Library
{
    [Serializable]
    public class Team
    {
        #region Constructor

        public Team()
        {
            this.GUID = Guid.NewGuid().ToString();
            this.AffiliationGUID = string.Empty;
            this.Name = "Nome do Time";
            this.FoundingDate = DateTime.Now;
            this.Athletes = new AthleteCollection();
        }

        public Team(string name,
                    DateTime foundingDate,
                    string flagName,
                    string affiliationGUID) : this()
        {
            this.Name = name;
            this.FoundingDate = foundingDate;
            this.FlagName = flagName;
            this.AffiliationGUID = affiliationGUID;
        }

        #endregion

        #region Attributes and Properties

        private string _GUID;
        public string GUID
        {
            get 
            {
                if (this._GUID == null)
                    this._GUID = Guid.NewGuid().ToString();
                return this._GUID; 
            }
            set
            {
                this._GUID = value;
                this.Notifier.RaisePropertyChanged("GUID");
            }
        }

        private string _name;
        public string Name
        {
            get { return this._name; }
            set 
            {
                this._name = value;
                this.Notifier.RaisePropertyChanged("Name");
            }
        }

        private DateTime _foundingDate;
        public DateTime FoundingDate
        {
            get { return this._foundingDate; }
            set 
            {
                this._foundingDate = value;
                this.Notifier.RaisePropertyChanged("FoundingDate");
            }
        }

        private string _flagName;
        public string FlagName
        {
            get { return this._flagName; }
            set 
            {
                this._flagName = value;
                this.Notifier.RaisePropertyChanged("FlagName");
            }
        }

        private string _affiliationGUID;
        public string AffiliationGUID
        {
            get { return this._affiliationGUID; }
            set 
            {
                this._affiliationGUID = value;
                this.Notifier.RaisePropertyChanged("AffiliationGUID");
            }
        }

        private AthleteCollection _athletes;
        public AthleteCollection Athletes
        {
            get { return this._athletes; }
            set { this._athletes = value; }
        }

        [NonSerialized]
        private ChangesNotifier<Team> _notifier;
        public ChangesNotifier<Team> Notifier
        {
            get 
            { 
                if (this._notifier == null)
                    this._notifier = new ChangesNotifier<Team>(this);
                return this._notifier;
            }
        }

        #endregion

        #region Overriden Methods

        public override string ToString()
        {
            return this.Name;
        }

        #endregion
    }
}
